<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
var jsonObj=new Object();
$(function(){
	
	var determine = false;
	if($("#roleName").val()!="ADMINISTRATOR" || $("#roleName").val()==null){
		determine = true;
		$("#deleteButton").hide();
	}
	
	$("#searchButton").click(function(){
		$('#somethingLostList').datagrid({ queryParams:getParams()});
	});
	
	$("#empty").click(function(){
		$("#title").textbox('setValue',"");
		$("#receiveState").combobox('setValue',"");
		$('#somethingLostList').datagrid({ queryParams:getParams()});
	});
	
	$("#deleteButton").click(function(){
		var id = "";
		var checkedObj=$("input[name='id']:checked");
		if(checkedObj.size()==1){
			id = $("input[name='id']:checked").val();
			if(id!=null){
				$.messager.confirm({
					title:'提示',
					msg:'确定删除吗?',
					top:35,
					fn:function(r){
						if(r){
							$.ajax({
								type:'POST',
								url:'somethingLostDelete.action',
								data:{id:id},
								datatype:'json',
								success:function(msg){
									if(msg.status == "200"){
										$('#somethingLostList').datagrid({ queryParams:getParams()});
									}else{
										$.messager.alert("提示","删除失败");
									}
								}
							});
						}
					}
				});
			}
		}else{
			$.messager.alert("提示","选择一条记录请");
		}
	});
	
	$('#somethingLostList').datagrid({
	    url:'<c:url value="GetComethingLostList.action"/>',
	    queryParams:getParams(),//提交参数
	    toolbar:'#carCategoryToolbar',//表头工具栏
	    pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    pageList:[10, 20, 30, 40], 
	    fitColumns:true,
	    //checkOnSelect:true,
	    selectOnCheck:false,
	    //sortName: 'userName',
	    //sortOrder: 'asc',
	    remoteSort: false,
	    singleSelect:false,
	    //fitColumns:false,
	    //multiSort:true,
	    rownumbers:true,
	    //checkOnSelect:true,
	    striped:true,
	    singleSelect:false,
	    //singleSelect:true,
	    columns:[[
			{field:'id',title:'',width:20,hidden:determine,formatter: function(value,row,index){
				return '<input name="id" type="checkbox" value="'+value+'" />';
			}},
			{field:'title',title:'物品',align:'center',width:50,formatter:function(value,row,index){
				return "<a href='comethingLostShow.action?id="+row.id+"'>"+value+"</a>";
			}},
			{field:'content',title:'描述',width:300,align:'center'},
			{field:'releasePeople',title:'发布者',align:'center',width:80},
			{field:'college',title:'所属学院',align:'center',width:80},
			{field:'createTime',title:'发布时间',align:'center',width:100,sortable:true,formatter: function(value,row,index){
				var str="";
				if(value){
					str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss").replace(" ","<br/>");
				}
				return str;
			}},
			{field:'status',title:'状态',align:'center',width:50,formatter: function(value,row,index){
				if(value==1)
					return '【待领】';
				else
					return '已领';
			}},
	    ]],
	    onClickRow:function(index,row){
		    $("input[type=checkbox]").val([row.id]).attr("checked",true);
		    }
	});
});

function getParams(){
	if($("#title").val()!="" && $("#title").val()!=null){
		jsonObj.title=$("#title").val();
	}else{
		jsonObj.title=null;
	}
	if($("#receiveState").combobox('getValue')!="" && $("#receiveState").combobox('getValue')!=null){
		jsonObj.status=$("#receiveState").combobox('getValue');
	}else{
		jsonObj.status=null;
	}
	return jsonObj;
}